import GChild from "../../../Core/GView/GChild";
import { LNumber } from "../../Common/Language";
import { MapWrap } from './../../../Core/FrameEx/ES5Ex';
import { Res } from './../../Common/UIResources';
import { JXBtlCamp } from './JXBattleDefine';



const { ccclass, property, menu } = cc._decorator;

@ccclass @menu('JXRB/JXRBRoleHead')
export default class JXRBRoleHead extends GChild {
	@property(cc.Sprite) hpBar: cc.Sprite = null;
	@property(cc.Label) lv: cc.Label = null;
	@property(cc.Label) nameLb: cc.Label = null;
	@property(cc.Node) buffCnt: cc.Node = null;
	@property(cc.Label) lb_hp: cc.Label = null;
	protected _buffs: MapWrap<number, number> = new MapWrap<number, number>();



	public setName(sName: string, color: cc.Color) {
		this.nameLb.string = sName;
		this.nameLb.node.color = color;
	}

	public hideHpBar() {
		this.node.active = false;
	}

	public setHp(nTotal: number, nCur: number) {
		let isActive = this.node.active;
		this.node.active = true;
		let fillRange = nCur / nTotal;
		this.lb_hp.string = `${LNumber(nCur)}/${LNumber(nTotal)}`;
		cc.tween(this.hpBar).to(1, { fillRange: fillRange }).call(() => {
			if (!isActive) this.node.active = false;
		}).start()
	}

	public setLv(lv: number) {
		this.lv.string = lv.toString();
	}

	/** 设置护盾 */
	public setTempHp(tempHp: number, nTotal: number /** 最大血量 */) {

	}

	public setHpBarColor(camp: JXBtlCamp) {
		let barSprite = this.hpBar;
		let prBarSpName = camp == JXBtlCamp.Defenser ? "ui_xl_lv" : "ui_xl_ho"
		this.assetImpl.spriteAtlasFrame(barSprite, Res.texture.fight.ui, prBarSpName);
	}

}